Register-Lib PowerShell.Types

function Import-Assembly($name, $filename, [switch]$passthru=$false) {
    if($name){
        $a = [Reflection.Assembly]::LoadWithPartialName($name)
    }
    elseif($filename){
	   $a = [Reflection.Assembly]::LoadFile(($filename | Get-Item ).FullName)
    }
    if($passthru){
        $a
    }
}
Set-Alias Import Import-Assembly


function Inspect-Assembly ($a)
{
	try { return $a.GetTypes() } catch { $_.Exception.LoaderExceptions | % { Log $_.Message } }
}

function Inspect-Assemblies(){
	ls *.dll | % { Log $_.FullName; $a = inspect-assembly (import $_)}
}



## New-GenericObject.ps1 
## Creates an object of a generic type: 
## 
## Usage: 
## 
##   # Simple generic collection 
##   $list = New-GenericObject System.Collections.ObjectModel.Collection System.Int32 
## 
##   # Generic dictionary with two types 
##   New-GenericObject System.Collections.Generic.Dictionary System.String,System.Int32
## 
##   # Generic list as the second type to a generic dictionary 
##   $secondType = New-GenericObject System.Collections.Generic.List Int32 
##   New-GenericObject System.Collections.Generic.Dictionary System.String,$secondType.GetType()
## 
##   # Generic type with a non-default constructor 
##   New-GenericObject System.Collections.Generic.LinkedListNode System.Int32 10
## 
function New-GenericObject {

    param( 
        [string] $typeName = $(throw "Please specify a generic type name"),
        [string[]] $typeParameters = $(throw "Please specify the type parameters"),
        [object[]] $constructorParameters 
        ) 

    ## Create the generic type name 
    $genericTypeName = $typeName + '`' + $typeParameters.Count 
    $genericType = [Type] $genericTypeName 

    if(-not $genericType) 
    { 
        throw "Could not find generic type $genericTypeName" 
    } 

    ## Bind the type arguments to it 
    [type[]] $typedParameters = $typeParameters 
    $closedType = $genericType.MakeGenericType($typedParameters) 
    if(-not $closedType) 
    { 
        throw "Could not make closed type $genericType" 
    } 

    ## Create the closed version of the generic type 
    ,[Activator]::CreateInstance($closedType, $constructorParameters)
}

function Get-GenericType {

    param( 
        [string] $typeName = $(throw "Please specify a generic type name"),
        [string[]] $typeParameters = $(throw "Please specify the type parameters")
        ) 

    ## Create the generic type name 
    $genericTypeName = $typeName + '`' + $typeParameters.Count 
    $genericType = [Type] $genericTypeName 
        ## Bind the type arguments to it 
    [type[]] $typedParameters = $typeParameters 
    $closedType = $genericType.MakeGenericType($typedParameters) 
    if(-not $closedType) 
    { 
        throw "Could not make closed type $genericType" 
    } 
    return $closedType

}


# Function Add-Enum
# requires -version 2
#
# /\/\o\/\/ 2008
# Http://thePowerShellGuy.com

Function Add-Enum ($name,[string[]]$values,$nameSpace) {

if ($nameSpace) {

$code = @"
  namespace $NameSpace
  {
      public enum $name : int 
      {
          $($values -join ",`n")
      }
  }
"@

} else {

$code = @"
  public enum $name : int 
  {
      $($values -join ",`n")
  }
"@

}

  Add-Type $code 

}

filter Gac-Item { gacutil.exe /nologo /i $_}

function MSDN {
    param (
        [Parameter(ValueFromPipeline=$true)]
        $Item
    )
    if($Item -is [System.Type]){
        $type = $item
    } else {
        $type = $item.GetType()
    }
     if (($global:MSDNViewer -eq $null) -or ($global:MSDNViewer.HWND -eq $null)) {
        $global:MSDNViewer = new-object -ComObject InterNetExplorer.Application 
     } 
     $Uri = "http://msdn2.microsoft.com/library/" + $type.FullName + ".ASPX" 
     $global:MSDNViewer.Navigate2($Uri) 
     $global:MSDNViewer.Visible = $TRUE 
}